package org.jheuristics.ga.operators.selectors;

import org.epanetgrid.otimizacao.ag.ViaveisSelector;
import org.jheuristics.Individual;
import org.jheuristics.ga.DefaultPopulation;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.GAStatus;
import org.jheuristics.ga.Population;
import org.jheuristics.ga.multiObjective.EuclidianDistanceAlgorithm;
import org.jheuristics.ga.operators.Selector;
import org.jheuristics.ga.transformations.DoubleFitnessToDoubleTransformation;
import org.jheuristics.ga.transformations.FitnessToDoubleTransformation;


/**
 * Implementa��o b�sica para sele��o dos indiv�duos representativos
 * @author vinicius
 *
 */
public class DefaultRepresentativosSelector implements Selector {

	private FitnessToDoubleTransformation[] transformations;

	/**
	 * @param numOfObjectivesFunctions
	 */
	public DefaultRepresentativosSelector(int numOfObjectivesFunctions) {
		transformations = new FitnessToDoubleTransformation[numOfObjectivesFunctions];
		for (int i = 0 ; i < numOfObjectivesFunctions; i++) {
			transformations[i] = new DoubleFitnessToDoubleTransformation();
		}
	}
	
	/* 
	 * Os objetos status e config nunca devem ser utilizados, pois semprem ser�o igual a null.
	 */
	public Individual[] select(Population population, int howMany, GAStatus status, GAConfig config) {
		Population viaveis =  new DefaultPopulation();
        viaveis.addIndividuals(new ViaveisSelector().select(population, 0, null, null));
        Population viaveisNaoDominados =  new DefaultPopulation();
        viaveisNaoDominados.addIndividuals(new NonDominatedSelector().select(viaveis, 0, null, null));
        
		return new GroupSelector(new EuclidianDistanceAlgorithm(transformations)).select(viaveisNaoDominados, Math.min(viaveisNaoDominados.size(), howMany), null, null);
	}

}
